/**
 * CopyRight(C) HNA eKing Tech co,.cl
 * @Author ke_wan
 * @date 2014-5-14
 */
package com.hnas.sys.web.system;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.hnas.core.dto.DTOPagedList;
import com.hnas.sys.service.system.AuthorityService;
import com.hnas.sys.service.system.UserAuthorityService;
import com.hnas.sys.service.system.criteria.UserAuthCriterial;
import com.hnas.sys.service.system.dto.DTOAuthority;
import com.hnas.sys.service.system.dto.DTOUserAuthority;

/**
 * @author ke_wan
 *
 */
@Controller
@RequestMapping("/backend/system/userAuthority")
@SessionAttributes (value={ "criteria" })
public class UserAuthorityController {
	private Logger log = LoggerFactory.getLogger(UserAuthorityController.class);
	@Autowired
	private UserAuthorityService userAuthorityService;
	@Autowired
	AuthorityService authorityService;
	
	@RequestMapping("/list")
	public String loadUserAuthority(ModelMap map, HttpServletRequest request,
			@ModelAttribute UserAuthCriterial criteria){
		
		try {
			String page = null;//request.getParameter((new ParamEncoder("userAuthorityTable")
//			.encodeParameterName(TableTagParameters.PARAMETER_PAGE)));
//			DTOPagedSearch<UserAuthCriterial> sc = new DTOPagedSearch<UserAuthCriterial>();
//			sc.setSearchCon(criteria);
//			if (null == page)
//				sc.setPageNo(1);
//			else
//				sc.setPageNo(Integer.parseInt(page));
//
//		sc.setPageSize(20);
//		sc.setTotalCount(-1);
//		
//		DTOPagedList<DTOUserAuthority> pg  = userAuthorityService.findUserAuthoruty(sc);
//		List<DTOAuthority> dtoAuthority = authorityService.loadAll();
//		map.put("resultSize", pg.getTotalCount());
//		map.put("pageSize", sc.getPageSize());
//		map.put("dtoAuthority", dtoAuthority);
//		map.put("dtoUserAuthority", pg.getList());
		map.put("criteria", criteria);
		} catch (Exception e) {
//			e.printStackTrace();
			try{

			}catch(Exception ex){
				
			}
		}
		return "backend/system/userAuthorities";
		
	}
	

//	@RequestMapping("/userAuthorityForm")
//	public String userAuthorityForm(ModelMap map, HttpServletRequest request,HttpServletResponse response,
//			@ModelAttribute("criteria") UserAuthCriterial criteria) throws Exception{
//		
//		List<DTOUserAuthority> dtoUserAuthority  = userAuthorityService.searchOutputUA(criteria);
//		response.setContentType("application/vnd.ms-excel;charset=GBK");
//		response.setHeader("Content-Disposition", "attachment; filename=userAuthorityForm.xls");
//		WritableWorkbook wwb = Workbook.createWorkbook(response.getOutputStream());
//		try {
//			String title = "权限人员报表";
//			jxl.write.WritableSheet ws = wwb.createSheet(title, 0);
//			String[] titles = new String[] {"序号","用户姓名","E网账号","部门","权限名称" };
//
//			WritableFont titleFont = new WritableFont(WritableFont.TIMES, 11,
//					WritableFont.BOLD, false);
//			WritableCellFormat format = new WritableCellFormat(titleFont);
//			format.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
//			format.setBackground(Colour.GRAY_25);
//
//			//共有几个字段；
//			int a=0;
//			for (int i = 0; i < titles.length; i++) {
//				Label labelC = new Label(i, 1, titles[i], format);
//				ws.addCell(labelC);
//				a++;
//			}
//
//			int n = 2;
//
//			WritableFont vFont = new WritableFont(WritableFont.TIMES, 11,
//					WritableFont.NO_BOLD, false);
//			WritableCellFormat vFormat = new WritableCellFormat(vFont);
//			vFormat.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
//		
//			
//			 for (Iterator<DTOUserAuthority> t = dtoUserAuthority.iterator(); t.hasNext();) {
//				 DTOUserAuthority ua = t.next();
//				 
//				
//				 
//				String[] values = new String[] {
//						n-1+"",
//						ua.getUserName(),
//						ua.getUserNo(),
//						ua.getDepartmentName(),
//						ua.getAuthorityName()
//
//				};
//
//				for (int i = 0; i < values.length; i++) {
//					Label labelC = new Label(i, n, values[i], vFormat);
//					ws.addCell(labelC);
//				}
//				n++;
//			}
//			 //合并第一行，显示文字
//			 WritableFont font1 = new WritableFont(WritableFont.TIMES,11,WritableFont.BOLD, false);
//				WritableCellFormat format1 = new WritableCellFormat(font1);
//				format1.setBackground(Colour.GREEN);
//			 ws.mergeCells(0, 0, a-1, 0);
//			 Label labelC = new Label(0, 0, "权限人员列表",format1);
//				ws.addCell(labelC);
//				
//				
//			wwb.write();
//		}catch(Exception e){
//			log.error("权限人员导出报错：",e);
//		}finally {
//			wwb.close();
//		}
//		return null;
//		
//		
//	}

}
